﻿Public Class ClassProjet
    Public Chemin As String
    Public Description As String
    'Public FichiersOuverts As System.Collections.Specialized.StringCollection
    Public ColArchives As ClassColArchives
    Public ColTaches As ClassColTaches
    Public ColHisto As ClassColHisto
    Public ColCode As ClassColMacros
    Public ColMarqueurs As ClassColMarqueurs
    Public ColFiltreScripts As ClassColMacros
    Public ColFragments As ClassColFragments
    Public ColTextTransform As ClassColTextTransform
    Public ColFiltreLDAP As System.Collections.Specialized.StringCollection
    Public FiltreLDAP As String
    Public ColDomainesLDAP As System.Collections.Specialized.StringCollection
    Public DomaineLDAP As String
    Public ColProprietesLDAP As System.Collections.Specialized.StringCollection
    Public ProprietesLDAP As String


    Public Sub New()
        Me.Description = "Nouveau projet"
        'Me.FichiersOuverts = New System.Collections.Specialized.StringCollection
        Me.ColFiltreLDAP = New System.Collections.Specialized.StringCollection
        Me.FiltreLDAP = ""
        Me.ColDomainesLDAP = New System.Collections.Specialized.StringCollection
        Me.DomaineLDAP = ""
        Me.ColProprietesLDAP = New System.Collections.Specialized.StringCollection
        Me.ProprietesLDAP = ""
        Me.ColMarqueurs = New ClassColMarqueurs
        Me.ColFiltreScripts = New ClassColMacros
        Me.ColFragments = New ClassColFragments
        Me.ColTextTransform = New ClassColTextTransform
        Me.ColTaches = New ClassColTaches
        Me.ColHisto = New ClassColHisto
        Me.ColArchives = New ClassColArchives
        Me.ColCode = New ClassColMacros
    End Sub

    Public Sub Clear()
        'Me.FichiersOuverts.Clear()
        Me.ColMarqueurs.Clear()
        Me.ColFragments.Clear()
        Me.ColHisto.Clear()
        Me.ColFiltreLDAP.Clear()
        Me.ColFiltreScripts.Clear()
        Me.ColCode.Clear()
        Me.ColArchives.Clear()
        Me.ColTextTransform.Clear()
    End Sub

    Public ReadOnly Property Titre() As String
        Get
            If Me.Chemin = Form1.sProjetTemp Then
                Return ""
            Else
                Return System.IO.Path.GetFileNameWithoutExtension(Me.Chemin)
            End If
        End Get
    End Property

    Public Sub Edit(ByVal Onglet As Integer)
        FormProjet.Text = Me.Titre
        If Me.Titre = "" Then Me.Description = "Projet par défaut utilisé pour conserver les paramètres courants."
        FormProjet.TextBoxDescription.ReadOnly = (Me.Titre = "")
        FormProjet.TextBoxDescription.Text = Me.Description
        FormProjet.TabControl1.SelectedIndex = Onglet
        'TEST - AFFICHAGE DU CONTENU DANS UN LISTVIEW
        FormProjet.ListViewContenu.Items.Clear()
        FormProjet.ListViewContenu.Groups.Clear()
        Dim oGroupContenu As ListViewGroup
        Dim oItemContenu As ListViewItem
        oGroupContenu = FormProjet.ListViewContenu.Groups.Add("Marqueurs", Form1.ListViewMarqueurs.Items.Count & " marqueurs")
        For Each oItem As ListViewItem In Form1.ListViewMarqueurs.Items
            oItemContenu = FormProjet.ListViewContenu.Items.Add(oItem.Clone)
            oItemContenu.ImageKey = "Marqueur"
            oItemContenu.Group = oGroupContenu
        Next
        oGroupContenu = FormProjet.ListViewContenu.Groups.Add("Macros", Me.ColCode.Count & " macros")
        For Each oMacro As ClassMacro In Me.ColCode
            oItemContenu = FormProjet.ListViewContenu.Items.Add(oMacro.Titre, "Macro")
            oItemContenu.Tag = oMacro
            oItemContenu.Group = oGroupContenu
        Next
        oGroupContenu = FormProjet.ListViewContenu.Groups.Add("Fragments", Me.ColFragments.Count & " fragements de texte")
        For Each oFragment As ClassFragment In Me.ColFragments
            oItemContenu = FormProjet.ListViewContenu.Items.Add(oFragment.Titre, "Fragment")
            oItemContenu.Tag = oFragment
            oItemContenu.Group = oGroupContenu
        Next
        oGroupContenu = FormProjet.ListViewContenu.Groups.Add("Transformations", Me.ColTextTransform.Count & " transformations combinées")
        For Each oTrans As ClassTextTransform In Me.ColTextTransform
            oItemContenu = FormProjet.ListViewContenu.Items.Add(oTrans.Titre, "Transformation")
            oItemContenu.Tag = oTrans
            oItemContenu.Group = oGroupContenu
        Next
        oGroupContenu = FormProjet.ListViewContenu.Groups.Add("Remplacements", Me.ColFiltreScripts.Count & " remplacements scriptés")
        For Each oMacro As ClassMacro In Me.ColFiltreScripts
            oItemContenu = FormProjet.ListViewContenu.Items.Add(oMacro.Titre, "Macro")
            oItemContenu.Tag = oMacro
            oItemContenu.Group = oGroupContenu
        Next
        For Each oItem As ListViewItem In Form1.ListViewFichiers.Items
            Dim oDoc As ClassDocument = oItem.Tag
            oGroupContenu = FormProjet.ListViewContenu.Groups.Add(oDoc.ID, oDoc.Historique.Liste.Count - 1 & " versions pour " & oDoc.Titre)
            Dim NoArchive As Integer = 0
            For Each oArchive As ClassArchive In oDoc.Historique.Liste
                If Not oArchive Is Nothing Then
                    NoArchive += 1
                    oItemContenu = FormProjet.ListViewContenu.Items.Add("Archive " & NoArchive & " (" & oArchive.DateFichier & ")", "Archive")
                    oItemContenu.Tag = oArchive
                    oItemContenu.Group = oGroupContenu
                End If
            Next
        Next
        'Affichage des infos générales
        Dim oInfo As System.IO.FileInfo = My.Computer.FileSystem.GetFileInfo(Me.Chemin)
        FormProjet.LabelInfo10.Text = "Dernière modif " & oInfo.LastWriteTime.ToString()
          'Récupération des activités
        FormProjet.ListViewActivites.Items.Clear()
        For Each oTache As ClassTache In Me.ColTaches
            Dim oItem As ListViewItem = FormProjet.ListViewActivites.Items.Add(oTache.Titre, "Activite")
            oItem.Tag = oTache
            oItem.Checked = oTache.Terminee
            oItem.SubItems.Add(oTache.DateTerminee)
        Next
        'Affichage
        If FormProjet.ShowDialog = DialogResult.OK Then
            Me.Description = FormProjet.TextBoxDescription.Text
            Me.ColTaches.Clear()
            For Each oItem As ListViewItem In FormProjet.ListViewActivites.Items
                Dim oTache As ClassTache = oItem.Tag
                Me.ColTaches.add(oTache.Titre, oTache)
            Next
        End If
    End Sub
End Class
